﻿using PracticeCentre.Business;
using PracticeCentre.Common;
using PracticeCentre.Modeles;
using PracticeCentre.Mvc.Helper;
using PracticeCentre.Mvc.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace PracticeCentre.Mvc.Controllers
{
    public class RecruitmentController : Controller
    {
        private JsonResult result;
        // GET: Recruitment
        public ActionResult RecruitmentAction()
        {
            return View();
        }
        [HttpPost]
        public ActionResult RecruitmentAction(PageViewModel model)
        {
            Recruitment ment = new Recruitment();
            PageModel<RecruitmentState> list = new PageModel<RecruitmentState>();
            list.PageSize = model.PageSize;
            list.PageNumber = model.PageNumber;
            list = ment.GetPlanList(list);
            string Data = JsonTool.JsonSerializer(list);
            result = DataHelper.GetResult(ExecuteState.Succeed, "获取列表成功！", Data);
            return result;
        }
        public ActionResult RecruitmentParticulars(int id)
        {
            return View();
        }
        /// <summary>
        /// 显示招聘请求
        /// </summary>
        /// <returns></returns>
        public ActionResult Recruitment()
        {
            return View();
        }
        /// <summary>
        /// 显示招聘请求
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult Recruitment(PageViewModel page)
        {
            PageModel<View_Recruitment> pagemodel = ModelesMapping.Mapping<PageModel<View_Recruitment>, PageViewModel>(page);
            Recruitment recruitment = new Recruitment();
            pagemodel = recruitment.GetPlanList(pagemodel);
            string data = JsonTool.JsonSerializer(pagemodel);
            result = DataHelper.GetResult(ExecuteState.Succeed, "获取列表成功！", data);
            return result;
        }
        /// <summary>
        /// 审批招聘需求
        /// </summary>
        /// <param name="page"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult Approve(CreatePlan page)
        {
            result = new JsonResult();
            //登陆人ID
            page.UserID = 1;
            if ((page.ReitRemark == null | page.ReitRemark == "") && page.ReitState == 0)
            {
                result.Data = new
                {
                    state = 0,
                    Message = "请输入拒绝原因."
                };
                return result;
            }
            if (page.ReitRemark == null)
            {
                page.ReitRemark = "";
            }
            Recruitment recruitment = new Recruitment();
            if (recruitment.UpdateApprove(page))
            {
                result.Data = new
                {
                    state = 1,
                    Message = "审批成功!"
                };
            }
            else
            {
                result.Data = new
                {
                    state = 0,
                    Message = "审批失败!"
                };
            }
            return result;
        }
        public ActionResult select()
        {
            return View();
        }
        /// <summary>
        /// 计划周期查询
        /// </summary>
        /// <param name="page"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult select(PageViewModel page)
        {
            //将视图数据映射到业务逻辑数据
            Recuritselect per = new Recuritselect();
            PageModel<AddressView> pagemodel = new PageModel<AddressView>();
            pagemodel.PageSize = page.PageSize;
            pagemodel.PageNumber = page.PageNumber;
            pagemodel.Where = page.Where;
            pagemodel = per.GetPlanList(pagemodel);
            JsonResult result = new JsonResult();
            result.Data = new
            {
                Sate = 0,
                Message = "获取数据成功",
                Data = JsonTool.JsonSerializer(pagemodel)
            };
            return result;

        }
		
			public ActionResult RequireAdd()
        {
           
            return View();
        }
        [HttpPost]
        /// <summary>
        /// 表单数据添加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        
        public ActionResult RequireAdd(RecruitmentsAdd model)
        {  //通过ajax data 传值（表单元素的值 ）

            int PostName = Convert.ToInt32(Request.Form["PostName"]);
            int amount = Convert.ToInt32(Request["amount"]);
            DateTime arriveTime = Convert.ToDateTime(Request["arrivetime"]);
            string duits = Request.Form["duties"];
            string Require = Request["require"];
            int dept = Convert.ToInt32(Request.Form["DeptName"]);
            
           
           
          

            //   赋值给model层
            model.PostID = PostName;
            model.ReitAmount = amount;
            model.ReportTime = arriveTime;
            model.Obligation = duits;
            model.Require = Require;
            model.CreateTime=DateTime.Now;
            model.DeptID= dept;
            model.UserID =2;
            model.ReitState =2;
            model.ReitRemark ="";



            //调用
            Recruitment recruitment = new Recruitment();
            bool succeed = recruitment.RecuriAdd(model);
            result = new JsonResult();
            result.Data = new {
                Sate = 0,
                Message = "添加数据成功",
                Data = JsonTool.JsonSerializer(succeed)
            };
            return result;

           
        }
        [HttpPost]
        /// <summary>
        /// 读取岗位 绑定下拉框数据
        /// </summary>
        /// <returns></returns>
        public ActionResult PostSelect()
        {
            //查询岗位列表信息


            //model.PostName;
            Recruitment personal = new Recruitment();
            List<Position> model= personal.GetAllPostList();
            string jsonString=JsonTool.JsonSerializer(model);
            JsonResult json = DataHelper.GetResult(ExecuteState.Succeed, "", jsonString);

            return json;
          }
        [HttpPost]
        /// <summary>
        /// 读取部门 绑定下拉框数据
        /// </summary>
        /// <returns></returns>
        public ActionResult DeptSelect()
        {
            //查询部门列表信息


            //model.PostName;
            Recruitment personal = new Recruitment();
            List<Department> model = personal.GetAllDeptList();
            string jsonString = JsonTool.JsonSerializer(model);
            JsonResult json = DataHelper.GetResult(ExecuteState.Succeed, "", jsonString);

            return json;
        }
		public ActionResult State()
        {
            return View();
        }
        [HttpPost]
        public ActionResult State(PageViewModel page)
        {
            PageModel<RecruitmentState> pagemodel = ModelesMapping.Mapping<PageModel<RecruitmentState>, PageViewModel>(page);
            Recruitment recruitment = new Recruitment();
            pagemodel = recruitment.GetPlanList(pagemodel);
            string data = JsonTool.JsonSerializer(pagemodel);
            result = DataHelper.GetResult(ExecuteState.Succeed, "获取列表成功！", data);
            return result;
        }
		
    }
}